﻿namespace Rules
{
    public class MinLengthRule : RuleBase<string>
    {
        public MinLengthRule(int minLength, string propertyName)
            : base(propertyName)
        {
            MinLength = minLength;
        }

        public MinLengthRule(int minLength, string propertyName, string description)
            : base(propertyName, description)
        {
            MinLength = minLength;
        }

        public int MinLength { get; private set; }

        protected override bool DoEvaluate(string subject)
        {
            return string.IsNullOrEmpty(subject) || subject.Length >= MinLength;
        }

        protected override string GetDefaultDescription()
        {
            return string.Format("{0} must be at least {1} characters long", PropertyName, MinLength);
        }
    }
}